<?php
namespace App\Models\Traits;

use Cache;
use Image;
trait PictuerMd5Helper
{
  public function setMd5()
  {
    if ($pictuer = $this->getNotMd5Pictuer()) {
      $md5 = $this->downLoadPictuer($pictuer);
      $pictuer->update(['md5' => $md5]);
      return $md5;
    }
    return false;
  }
  protected function downLoadPictuer($pictuer)
  {

      $url = 'http://touxiangge.oss-cn-shenzhen-internal.aliyuncs.com';
      $pictuer_url = $url . '/' . $pictuer->path . '/' . $pictuer->filename;
      $file = file_get_contents($pictuer_url);
      return md5($file);
  }
  protected function getNotMd5Pictuer()
  {
    return $this->where('md5', null)->first();
  }
}
